using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Toast.Compression;
using Toast.ContentDeliveryNetworks;
using Toast.ContentTypes;
using Toast.Core;
using Toast.Extensions;

namespace Toast.DemoSite
{
    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" });
        }

        public override void Init()
        {
            base.Init();
            ToastCore.Initialize(this);
        }

        public void ConfigureScriptBehind()
        {
             ToastCore.SeperateFiles = false;

            ToastCore.Compression(compressor =>
                {
                    compressor.DefaultForJavaScriptIs<PackerCompression>(CompressionLevel.High);
                    compressor.DefaultForCssIs<YUICssCompression>();
                });

            ToastCore.CommonContent(content =>
                {
                    content.Add(GoogleAjaxLibraries.Get("jquery", "1.4.2"));
                    content.Add(Content.From("/Scripts/DemoScriptContent.js", CompressorFactory.Get<PackerCompression>()));
                    content.Add(MultipleContent.UsingWildCardSearch("/Scripts/Common/*.js"));

                    content.Add(Content.From("/Content/Site.css"));
                });
        }

        protected void Application_Start()
        {

            ConfigureScriptBehind();
            RegisterRoutes(RouteTable.Routes);
        }
    }
}